package View;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashSet;
import java.util.Set;

import javax.swing.*;
import javax.swing.border.EmptyBorder;

import Controller.*;
import Model.Contact;
import Model.ContactsList;

/**
 * ListContactPane is the pane which contains the list of the contacts
 * and the buttons to sort the list
 * @author Johanna
 *
 */
public class ListContactsPane extends JPanel {

	private JList listing;
	private DefaultListModel defaultList;

	private JButton alphaOrderButton;
	private JButton timeOrderButton;
	//private JComboBox letterButton;
	//private JComboBox groupButton;

	private JPanel topPane;

	public static final String ALPHA_ORDER = "Alphabetical order";
	public static final String TIME_ORDER = "Sort by newest contacts";
	public static final String GROUP_ORDER = "Sort by groups";
	public static final String LETTER_ORDER = "Sort by first letter";
	
	public final String[] LETTERS = { "- Select a letter -", "Everyone", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
			"O", "P", "Q", "R", "S","T", "U", "V", "W", "X", "Y", "Z"};
	public final String[] GROUPS = { "- Select a group -", "Everyone", "Family", "Work", "Friends", "Clients" };
	
	private JComboBox letterButton = new JComboBox(LETTERS);
	private JComboBox groupButton = new JComboBox(GROUPS);
	
	/** 
	 * Constructor
	 */
	public ListContactsPane() {

		setBorder(new EmptyBorder(15, 15, 15, 15));

		listing = new JList();
		defaultList = new DefaultListModel(); 

		// Create a new list
		listing = new JList( defaultList );
		listing.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		listing.setSelectedIndex(0);

		JScrollPane listScroll = new JScrollPane(listing);

		// Buttons
		this.topPane = new JPanel(new GridLayout(2,2,5,5));
		this.topPane.setPreferredSize(new Dimension(340, 70));

		this.alphaOrderButton = new JButton(); 
		this.alphaOrderButton.setText(ALPHA_ORDER); 
		topPane.add(this.alphaOrderButton);

		topPane.add(this.letterButton);
		topPane.add(this.groupButton);

		add(topPane, BorderLayout.NORTH);
		add( listScroll, BorderLayout.SOUTH );
		listScroll.setPreferredSize(new Dimension(330,515));

		this.setPreferredSize(new Dimension(350, 700));
	}

	public void setDefaultList(DefaultListModel newList) {
		this.defaultList = newList;
	}

	public DefaultListModel getDefaultList(){
		return this.defaultList;
	}

	public JList getListing() {
		return listing;
	}

	public void setListing(JList newList) {
		listing = newList;
	}

	public JPanel getTopPane()
	{
		return this.topPane;
	}
	
	public JComboBox getLetterButton() {
		return this.letterButton;
	}
	
	public JComboBox getGroupButton() {
		return this.groupButton;
	}
	
	public JButton getAlphaOrderButton() {
		return this.alphaOrderButton;
	}
}
